<?php

/* 
 * Copyright (C) 2013 peter
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

include_once '../../credentials/includes/db_connect.php';
include_once '../../credentials/includes/psl-config.php';

$error_msg = "";

if (isset($_POST['field1'], $_POST['field2'], $_POST['field3'])) {
			
	$field1 = filter_input(INPUT_POST, 'field1', FILTER_SANITIZE_STRING);
	$field2 = filter_input(INPUT_POST, 'field2', FILTER_SANITIZE_STRING);
	$field3 = filter_input(INPUT_POST, 'field3', FILTER_SANITIZE_STRING);
	
    // Insert the new user into the database 
    if ($insert_stmt = $mysqli->prepare("INSERT INTO enter_table_name (field1, field2, field3) VALUES (:field1, :field2, :field3)")) {
         $insert_stmt->bind_param(':field1', $field1, PDO::PARAM_STR);
		 $insert_stmt->bind_param(':field2', $field2, PDO::PARAM_STR);
		 $insert_stmt->bind_param(':field3', $field3, PDO::PARAM_INT);
		 
         // Execute the prepared query.
         if (! $insert_stmt->execute()) {
             header('Location: ../../credentials/error.php?err=MYSQL ERROR: INSERT');
             exit();
         }
    }
	else
		echo "An error occured: $error_msg";
    
}